package refunds

// ==================== 退款通知消息 ====================

// RefundsNotifyMessage 退款结果回调通知
type RefundsNotifyMessage struct {
	// Status 状态 1：待确认 2：成功 3：失败
	Status string `json:"status,omitempty"`
	// Summary 回调描述
	Summary string `json:"summary,omitempty"`
	// MchID 商户号
	MchID string `json:"mch_id,omitempty"`
	// TransactionID 平台订单号
	TransactionID string `json:"transaction_id,omitempty"`
	// OutTradeNo 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// ChnTransactionID 渠道订单号
	ChnTransactionID string `json:"chn_transaction_id,omitempty"`
	// OriOutTradeNo 原外部订单号
	OriOutTradeNo string `json:"ori_out_trade_no,omitempty"`
	// OriTransactionID 原平台订单号
	OriTransactionID string `json:"ori_transaction_id,omitempty"`
	// TotalFee 交易金额
	TotalFee interface{} `json:"total_fee,omitempty"`
	// TransTime 交易时间
	TransTime string `json:"trans_time,omitempty"`
	// SuccessTime 退款完成时间
	SuccessTime string `json:"success_time,omitempty"`
}

// NewRefundsNotifyMessage 创建退款通知消息
func NewRefundsNotifyMessage() *RefundsNotifyMessage {
	return &RefundsNotifyMessage{}
}

// NewRefundsNotifyMessageFromMap 从map创建退款通知消息
func NewRefundsNotifyMessageFromMap(dataMap map[string]interface{}) *RefundsNotifyMessage {
	message := &RefundsNotifyMessage{}

	if status, ok := dataMap["status"].(string); ok {
		message.Status = status
	}
	if summary, ok := dataMap["summary"].(string); ok {
		message.Summary = summary
	}
	if mchID, ok := dataMap["mch_id"].(string); ok {
		message.MchID = mchID
	}
	if transactionID, ok := dataMap["transaction_id"].(string); ok {
		message.TransactionID = transactionID
	}
	if outTradeNo, ok := dataMap["out_trade_no"].(string); ok {
		message.OutTradeNo = outTradeNo
	}
	if chnTransactionID, ok := dataMap["chn_transaction_id"].(string); ok {
		message.ChnTransactionID = chnTransactionID
	}
	if oriOutTradeNo, ok := dataMap["ori_out_trade_no"].(string); ok {
		message.OriOutTradeNo = oriOutTradeNo
	}
	if oriTransactionID, ok := dataMap["ori_transaction_id"].(string); ok {
		message.OriTransactionID = oriTransactionID
	}
	if totalFee, ok := dataMap["total_fee"]; ok {
		message.TotalFee = totalFee
	}
	if transTime, ok := dataMap["trans_time"].(string); ok {
		message.TransTime = transTime
	}
	if successTime, ok := dataMap["success_time"].(string); ok {
		message.SuccessTime = successTime
	}

	return message
}

// ToMap 转换为map
func (m *RefundsNotifyMessage) ToMap() map[string]interface{} {
	return map[string]interface{}{
		"status":             m.Status,
		"summary":            m.Summary,
		"mch_id":             m.MchID,
		"transaction_id":     m.TransactionID,
		"out_trade_no":       m.OutTradeNo,
		"chn_transaction_id": m.ChnTransactionID,
		"ori_out_trade_no":   m.OriOutTradeNo,
		"ori_transaction_id": m.OriTransactionID,
		"total_fee":          m.TotalFee,
		"trans_time":         m.TransTime,
		"success_time":       m.SuccessTime,
	}
}
